Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve endianness validation strategy #10

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amitsr4
Copy link
Collaborator

@amitsr4 amitsr4 commented Dec 31, 2024

Fixed #9

  • Replacing runtime exceptions with compile-time #error in C++
  • Adding JavaScript-side endianness validation pre-WASM load
  • Removing redundant runtime checks from C++ implementation
  • Updating TypeScript initialization with early validation

@ofriw
Copy link
Collaborator

ofriw commented Dec 31, 2024

Looks like you forgot to attach the actual cpp code files

#define IS_BIG_ENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define IS_BIG_ENDIAN 0
#error "Big endian systems are not supported for compilation"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the wording to "TODO: Big Endian support"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@@ -21,28 +21,37 @@ interface BloomFilterModule extends EmscriptenModule {
UTF8ToString: (ptr: number) => string;
}

function checkEndianness(): boolean {
const buffer = new ArrayBuffer(2);
new DataView(buffer).setInt16(0, 256, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change it to a call to a CPP function that returns an endian value. We really care about the endianess of the WASM runtime not of the JS runtime.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve endianness checks: Move from runtime exceptions to compile-time and JS-side validation
2 participants